package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.dto.RoleDTO;
import com.miku.blog.domain.vo.UserVo;
import com.miku.blog.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * @author shkstart
 * @create ${}YEAR-05-31 22:11
 */

@Api(tags = "后台管理系统[角色]")
@RequestMapping("/admin")
@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    @SystemLog(notes = "获取角色列表(用户列表编辑菜单){后台管理系统}")
    @ApiOperation(value = "获取角色列表接口",notes = "获取角色列表接口 {用户列表编辑菜单}")
    @GetMapping("/users/role")
    public ResponseResult getRoleList(){
        return roleService.getRoleList();
    }


    @SystemLog(notes = "获取角色列表(角色管理菜单){后台管理系统}")
    @ApiOperation(value = "获取角色列表接口",notes = "获取角色列表接口 {角色管理菜单}")
    @GetMapping("/roles")
    public ResponseResult getRoles(@RequestParam("current")Integer current,
                                   @RequestParam("size")Integer size,
                                   @RequestParam(value = "keywords",required = false)String keywords)
    {
        return roleService.getRoles(current,size,keywords);
    }


    @SystemLog(notes = "禁用/启用角色{后台管理系统}")
    @ApiOperation(value = "禁用/启用角色接口")
    @PutMapping("/role/disable/{roleId}")
    public ResponseResult disable(@PathVariable("roleId") Integer roleId,
                                  @RequestParam("isDisable")Integer isDisable)
    {
        return roleService.disable(roleId,isDisable);
    }

    @SystemLog(notes = "删除(物理)角色{后台管理系统}")
    @ApiOperation(value = "删除(物理)角色接口")
    @DeleteMapping("/roles")
    public ResponseResult deleteRole(@RequestBody Integer[] roleIdList){
        return roleService.deleteRole(roleIdList);
    }

    @SystemLog(notes = "添加或修改角色{后台管理系统}")
    @ApiOperation(value = "添加或修改角色接口")
    @PostMapping("/role")
    public ResponseResult addRole(@RequestBody RoleDTO roleDTO){
        return roleService.addRole(roleDTO);
    }

}
